<?php
include_once(dirname(__FILE__) . "/service-adapter-base.php");
// include_once(dirname(__FILE__) . "/util.php");
// include_once(dirname(__FILE__) . "/account/account.php");

class ArticleMainAdapter extends ServiceAdapterBase {
  function __construct() {
    parent::__construct('127.0.0.1', '9093');
    $this->service_ = new ArticleMainClient($this->protocol_);
  }

  protected function LoadIDL() {
    require_once dirname(__FILE__) . '/gen-php/ServiceBase/ServiceBase.php';
    require_once dirname(__FILE__) . '/gen-php/ServiceBase/ServiceBase_types.php';
    require_once dirname(__FILE__) . '/gen-php/ArticleMain/ArticleMain.php';
    require_once dirname(__FILE__) . '/gen-php/ArticleMain/ArticleMain_types.php';
  }

  public function GetContent($article_id) {
    try{
      $res = $this->service_->GetContent($article_id);
      if ($res->success) {
        return stripslashes($res->content);
      }
    } catch (TException $tx) {
    }
    return null;
  }

  public function UpdateContent($article_id, $content) {
    try {
      $res = $this->service_->UpdateContent($article_id, $content);
      if ($res == 0) {
        return 0;
      }
    } catch (TException $tx) {
      return -1;
    }
    return -2;
  }
}
?>
